package com.example.sy2.demos.web.controller;

import com.example.sy2.demos.web.entity.Grade;
import com.example.sy2.demos.web.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/grades")
public class GradeController {
    @Autowired
    private GradeService gradeService;

    @GetMapping("/listAll")
    public ResponseEntity<List<Grade>> listAll() {
        return ResponseEntity.ok(gradeService.listAllGrades());
    }

    @GetMapping("/getByCourseId/{courseId}")
    public ResponseEntity<List<Grade>> getByCourseId(@PathVariable Long courseId) {
        return ResponseEntity.ok(gradeService.getGradesByCourseId(courseId));
    }

    @PostMapping("/update")
    public ResponseEntity<Void> update(@RequestBody Grade grade) {
        gradeService.updateGrade(grade);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/getByRange/{minScore}/{maxScore}")
    public ResponseEntity<List<Grade>> getByRange(@PathVariable BigDecimal minScore, @PathVariable BigDecimal maxScore) {
        return ResponseEntity.ok(gradeService.getGradesByScoreRange(minScore, maxScore));
    }
}
